package 扑克牌;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class Game {
    //定义一个花色的数组
    private final String[] decor={"♥","♦","♣","♠"};
    private final String[] colour={"红色","黑色"};
    public String getDecor(int x) {
        return decor[x];
    }

    public String getColour(int x) {
        return colour[x];
    }

    //买牌
    public  ArrayList<Pokers> BuyPokers() {
        //四种花色
        //两种颜色
        //13个数
        ArrayList<Pokers> arrayList=new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <=13 ; j++) {
                Pokers pokers=new Pokers(getDecor(i),j,getColour(i%2));
                arrayList.add(pokers);
            }
        }
        return arrayList;
    }
    //洗牌
    private void shuffle(ArrayList<Pokers> p) {
        Random random =new Random();
        for (int i = p.size()-1; i >0 ; i--) {
          int z= random.nextInt(i);
            swap(p,i,z);
        }
    }
    //交换
    private void swap(ArrayList<Pokers> p,int x,int y) {
        Pokers tmp=p.get(x);
        p.set(x,p.get(y));
        p.set(y,tmp);

    }
    public void PlayPokers(ArrayList<Pokers> p) {
        ArrayList<Pokers> p1=new ArrayList<>();
        ArrayList<Pokers> p2=new ArrayList<>();
        ArrayList<Pokers> p3=new ArrayList<>();
        ArrayList<ArrayList<Pokers>> p4=new ArrayList<>();
        p4.add(p1);
        p4.add(p2);
        p4.add(p3);
        shuffle(p);
        System.out.println(p);
        for (int i = 0; i <3 ; i++) {
            for (int j = 0; j < 3; j++) {
                p4.get(j).add(p.remove(0));
            }
        }
        for (int i = 0; i <3 ; i++) {
            System.out.println(p4.get(i));
        }
        System.out.println("剩下的牌"+p);
    }
    public static void main1(String[] args) {
        Game game=new Game();
       ArrayList<Pokers>p1= game.BuyPokers();
        System.out.println(p1);
        game.PlayPokers(p1);
    }

    public static void main(String[] args) {
        List<List<Integer>> list = new LinkedList<>();
        List<Integer> list1 = new LinkedList<>();
        List<Integer> list2 = new LinkedList<>();
        List<Integer> list3 = new LinkedList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list2.add(1);
        list2.add(2);
        list2.add(3);
        list3.add(1);
        list3.add(2);

        list3.add(3);
        //System.out.println(list.get(0));
    }
}
